package com.czq.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czq.dao.SetmealDao;
import com.czq.execption.BusinessEXception;
import com.czq.pojo.Dish;
import com.czq.pojo.Setmeal;
import com.czq.pojo.SetmealDish;
import com.czq.service.SetmealDishService;
import com.czq.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealDao, Setmeal> implements SetmealService {
    @Autowired
    private SetmealDishService setmealDishService;


    @Override
    public void delete(List<Long> ids) {

        for (Long id : ids) {
            LambdaQueryWrapper<Setmeal> query = new LambdaQueryWrapper<Setmeal>();
            query.eq(Setmeal::getStatus, 1);
            Setmeal s = this.getById(id);
            if (s == null) {
                this.removeById(id);
            } else {
                throw new BusinessEXception("该套餐正在售卖中，不可删除");
            }
            LambdaQueryWrapper<SetmealDish> q = new LambdaQueryWrapper<SetmealDish>();
            q.eq(SetmealDish::getSetmealId, id);
            List<SetmealDish> list = setmealDishService.list(q);
            setmealDishService.removeByIds(list);
//            for (SetmealDish dish : list) {
//                Long dishId = dish.getDishId();
//                LambdaQueryWrapper<Dish> dishquery=new LambdaQueryWrapper<Dish>();
//                dishquery.eq(Dish::getId,dishId);
//
//            }
//
        }


    }
}
